# -*- coding:UTF-8 -*-

import time
import json
from selenium import webdriver

cookie = {}
driver = webdriver.Chrome()
driver.get('https://mp.weixin.qq.com/')
time.sleep(2)
driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div/form/div[1]/div[1]/div/span/input').clear()
name = '1258875254@qq.com'
driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div/form/div[1]/div[1]/div/span/input').send_keys(name)
driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div/form/div[1]/div[2]/div/span/input').clear()
password = 'lsq910561556Wy'
driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div/form/div[1]/div[2]/div/span/input').send_keys(password)
time.sleep(2)
driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div/form/div[4]/a').click()
time.sleep(20)
cookies = driver.get_cookies()
for item in cookies:
    cookie[item.get('name')] = item.get('value')
with open('cookie.txt', 'w') as f:
    f.write(json.dumps(cookie, encoding='utf-8', ensure_ascii=False))
print cookies
